package controller;

import java.util.ArrayList;

import manager.CourseMgr;
import manager.CoursePreRequisiteMgr;
import entity.Course;
import exception.ValidationError;

public class CourseCtrl {

	private CourseMgr courseMgr;
	private CoursePreRequisiteMgr coursePreRequisiteMgr;

	public CourseCtrl() {
		courseMgr = new CourseMgr();
		coursePreRequisiteMgr = new CoursePreRequisiteMgr();
	}

	public void addCourse(String courseCode, String title, String description,
			String school, ArrayList<Course> preRequisites, String examDate,
			String examStartTime, String examEndTime) {

		courseMgr.addCourse(new Course(courseCode, title, description, school,
				examDate, examStartTime, examEndTime, preRequisites));
	}

	public void addPreRequisiteForCourse(String prerequisitesCode,
			String courseCode) {

		coursePreRequisiteMgr.addPreRequisiteForCourse(prerequisitesCode,
				courseCode);
	}

	public Course retrieveCourseForCourseCode(String courseCode)
			throws ValidationError {
		return courseMgr.retrieveCourseForCourseCode(courseCode);
	}

	public ArrayList<Course> retrieveAllCourses() {
		return courseMgr.retrieveAllCourses();
	}

	public ArrayList<Course> retrievePreRequisitesForCourse(String courseCode) {
		return coursePreRequisiteMgr.retrievePreRequisitesForCourse(courseCode);
	}

	public ArrayList<Course> retrieveCoursesOfferedBySchool(String school) {
		return courseMgr.retrieveCoursesOfferedBySchool(school);
	}

	public void deleteAllCourses() {
		courseMgr.deleteAllCourses();
	}

	public void deleteAllPreRequisites() {
		coursePreRequisiteMgr.deleteAllPreRequisites();
	}

	public boolean hasCourse(String courseCode) {
		try {
			retrieveCourseForCourseCode(courseCode);
		} catch (ValidationError e) {
			return false;
		}
		return true;
	}

}
